package com.one.controller;

import com.one.annotation.RequestPermission;
import com.one.annotation.RequestUser;
import com.one.constant.SystemConstant;
import com.one.service.UserCollectService;
import com.one.util.PageUtil;
import com.one.util.RequestReturn;
import com.one.vo.CollectFootpointVo;
import com.one.vo.UserVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

/**
 * @ClassName: UserCollectController
 * @Auther: yph
 * @Date: 2022/1/19 19:15
 * @Description: 用户收藏、足迹操作入口
 */
@Api(tags = "O用户足迹收藏操作入口")
@Slf4j
@RestController
public class UserCollectController {

    @Autowired
    private UserCollectService userCollectService;

    /**
     * @Author: yph
     * @Date: 2022/1/19 19:16
     * @return:
     * @Description: 用户查询收藏信息
     */
    @ApiOperation(value = "用户查询收藏信息", notes = "需要传token，用户登录之后可以查看自己的收藏信息")
    @RequestPermission
    @GetMapping("/queryCollectProduct")
    public RequestReturn<List<CollectFootpointVo>> queryCollectProduct(@ApiIgnore @RequestUser UserVo userVo) {
        return userCollectService.queryCollectProduct(userVo.getUserId());
    }

    /**
     * @Author: yph
     * @Date: 2022/1/19 19:21
     * @return:
     * @Description: 用户查询最近30天的浏览记录
     */
    @ApiOperation(value = "用户查询最近30天的浏览记录",notes = "需要用户登录")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNo",value = "分页起始页"),
            @ApiImplicitParam(name = "pageSize",value = "分页容量")
    })
    @RequestPermission
    @GetMapping("/queryFootpoint")
    public RequestReturn<PageUtil<List<CollectFootpointVo>>> queryFootpointByUserId(@ApiIgnore @RequestUser UserVo userVo,
                                                                                    @RequestParam(value = "pageNo", required = false) Integer pageNo,
                                                                                    @RequestParam(value = "pageSize", required = false) Integer pageSize) {
        if (pageNo == null || pageNo < 1) {
            pageNo = SystemConstant.PAGE_NUM;
        }
        if (pageSize == null || pageSize < 1) {
            pageSize = SystemConstant.PAGE_SIZE;
        }
        return userCollectService.queryFootpointByUserId(userVo.getUserId(), pageNo, pageSize);
    }

    /**
     * @Author: yph
     * @Date: 2022/1/19 15:26
     * @return:
     * @Description: 收藏/取消商品
     */
    @ApiImplicitParam(name = "productId",value = "商品id")
    @ApiOperation(value = "收藏/取消商品",notes = "需要登录，短时间内频繁操作会返回提示")
    @RequestPermission
    @GetMapping("/collectProduct")
    public RequestReturn<String> collectProduct(@ApiIgnore @RequestUser UserVo userVo,
                                                @RequestParam("productId") Integer productId) {
        return userCollectService.collectProduct(userVo.getUserId(), productId);
    }
    
    /**
     * @Author: yph
     * @Date: 2022/1/21 21:27
     * @return: 
     * @Description: 移入收藏，从购物车中将商品添加到收藏夹
    */

//    @ApiImplicitParam(name = "productId",value = "商品id")
    @ApiOperation(value = "移入收藏夹",notes = "从购物车中将商品添加到收藏夹，一次收藏多个商品信息")
    @RequestPermission
    @GetMapping("/collectProducts")
    public RequestReturn<String> collectProducts(@ApiIgnore @RequestUser UserVo userVo,
                                                @RequestParam("productId") List<Integer> productIds) {
        return userCollectService.collectProducts(userVo.getUserId(), productIds);
    }

    /**
     * @Author: yph
     * @Date: 2022/1/21 22:32
     * @return: 
     * @Description: 清空收藏夹
    */
    @ApiOperation(value = "清空收藏夹",notes = "一次性清空收藏夹中所有数据,需要用户登录")
    @RequestPermission
    @GetMapping("/clearUserCollect")
    public RequestReturn<String> clearUserCollect(@ApiIgnore @RequestUser UserVo userVo) {
        return userCollectService.clearUserCollect(userVo.getUserId());
    }
    
    /**
     * @Author: yph
     * @Date: 2022/1/21 23:29
     * @return: 
     * @Description: 清空历史记录
    */
    @ApiOperation(value = "清空历史记录",notes = "清空用户足迹,需要用户登录")
    @RequestPermission
    @GetMapping("/clearUserFootPoint")
    public RequestReturn<String> clearUserFootPoint(@ApiIgnore @RequestUser UserVo userVo) {
        return userCollectService.clearUserFootPoint(userVo.getUserId());
    }


}
